/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.behavior.iterator;

import java.util.List;

/**
 * @author lizhixing
 */
public class ConcreteIterator implements Iterator {

  private List<Object> list = null;
  private int index = -1;

  public ConcreteIterator(List<Object> list) {
    this.list = list;
  }

  @Override
  public boolean hasNext() {
    if (index < list.size() - 1) {
      return true;
    } else {
      return false;
    }
  }

  @Override
  public Object first() {
    index = 0;
    Object obj = list.get(index);
    return obj;
  }

  @Override
  public Object next() {
    Object obj = null;
    if (this.hasNext()) {
      obj = list.get(++index);
    }
    return obj;
  }
}
